package com.gxa.usermanagement.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.R;
import com.gxa.common.entity.usermange.VipUser;
import com.gxa.common.entity.usermange.VipUserAuditing;
import com.gxa.usermanagement.mapper.VipUserAuditingMapper;
import com.gxa.usermanagement.mapper.VipUserMapper;
import com.gxa.usermanagement.service.VipUserService;
import io.micrometer.core.instrument.Meter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class VipUserServiceImpl extends ServiceImpl<VipUserMapper, VipUser> implements VipUserService  {

    @Autowired
    private VipUserMapper vipUserMapper;
    @Autowired
    private VipUserAuditingMapper vipUserAuditingMapper;


    @Override
    public R updateVipUserService(Integer id, Integer state , VipUserAuditing vipUserAuditing) {
        vipUserMapper.updateVipUserStateMapper(id,state);
        if(state==2){
            //vipUserMapper.addVipUserAuditingMapper(vipUserAuditing);
            vipUserAuditingMapper.insert(vipUserAuditing);
        }

        //vipUserMapper.insert();
        R r = new R();
        r.setMessage("操作成功");
        r.setCode(200);
        return r;
    }

    @Override
    public R findVipUserByService(Integer currentPage, Integer pageSize, Integer id,String vipuserName,String vipuserPhone,String vipuserEmile,Integer state) {

        Integer start = (currentPage-1)*pageSize;
        Integer off = pageSize;
        List<VipUser> list = vipUserMapper.findVipUserByMapper(start, off,id,vipuserName,vipuserPhone,vipuserEmile,state);
        R r = new R();

        r.setMessage("查询成功");
        r.setCode(200);
        r.setData(list);
        return r;
    }


    @Override
    public R findVipUserAllService(Integer currentPage, Integer pageSize) {

        Integer start = (currentPage-1)*pageSize;
        Integer off = pageSize;
        List<VipUser> list = vipUserMapper.findVipUserAllMapper(start, off);
        Integer count = vipUserMapper.countUser();
        R r = new R();
        Map map = new HashMap<>();
        map.put("vipuser",list);
        map.put("count",count);
        r.setMessage("查询成功");
        r.setCode(200);
        r.setData(map);
        return r;
    }

    @Override
    public List<Long> findIdsByNickname(String vipuserName) {
        List<Long> ids = vipUserMapper.queryIdsByNickname(vipuserName);
        return ids;
    }

    @Override
    public VipUser findAllById(Long id) {
        R r = new R();
        VipUser vipUser = vipUserMapper.selectById(id);
//        r.setCode(200);
//        r.setMessage("查询成功");
//        r.setData(vipUser);
        return vipUser;
    }
}
